//
//  UpImageCell.m
//  Maintenance
//
//  Created by tox on 2017/9/18.
//  Copyright © 2017年 com.kaopudian. All rights reserved.
//

#import "UpImageCell.h"



@interface UpImageCell ()


@property (weak, nonatomic) IBOutlet UICollectionView *collectionVIew;

@end

@implementation UpImageCell
- (instancetype)initWithCoder:(NSCoder *)coder
{
    self = [super initWithCoder:coder];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.userInteractionEnabled = YES;
        self.accessoryView = nil;
        self.editingAccessoryView = nil;
        self.shouldIndentWhileEditing = NO;
    }
    return self;
}


- (void)awakeFromNib{
    [super awakeFromNib];
    
    CGFloat width = (kSCREEN_WIDTH-20-20)/6.0;
    UICollectionViewFlowLayout * layout = [UICollectionViewFlowLayout new];
    layout.itemSize = CGSizeMake(width, width);
    layout.minimumInteritemSpacing = 0;
    layout.minimumLineSpacing = 0;
    self.collectionVIew.collectionViewLayout = layout;
    self.collectionVIew.scrollEnabled = NO;
    [self.collectionVIew registerClass:[GroupCollectionView class] forCellWithReuseIdentifier:@"UICollectionViewCell"];

}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return self.nameArray.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    GroupCollectionView *cell = (GroupCollectionView *)[collectionView dequeueReusableCellWithReuseIdentifier:@"UICollectionViewCell" forIndexPath:indexPath];

    if(indexPath.item < self.nameArray.count){
        
        cell.lable.text = self.nameArray[indexPath.item];
    }
        cell.lable.textAlignment = 1;
    


    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    
        //跳转拉人
        if (self.block) {
           self.block(indexPath.row);
        }
     [self.collectionVIew reloadData];
}



+ (instancetype)cellWithTableView:(UITableView *)tableView{
    static NSString *cellID = @"UpImageCell";
    UpImageCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (!cell) {
        cell = [[NSBundle mainBundle]loadNibNamed:@"UpImageCell" owner:self options:nil].lastObject;
    }
    return cell;
}
@end
